/*
** init.c for asm in /home/vanet_c//proj-kw/asm
** 
** Made by charles-edouard vanet
** Login   <vanet_c@epitech.net>
** 
** Started on  Sat Dec  8 21:32:48 2012 charles-edouard vanet
** Last update Fri Dec 14 13:28:10 2012 charles-edouard vanet
*/

#include	"../includes/asm.h"

char	**init_tab(char **tab)
{
  tab = malloc(sizeof(char*) * 17);
  if (tab == NULL)
    my_error("", "", "Can't perform malloc.\n", 1);
  tab[0] = fill_name_tab(tab[0], "live", 4);
  tab[1] = fill_name_tab(tab[1], "ld", 2);
  tab[2] = fill_name_tab(tab[2], "st", 2);
  tab[3] = fill_name_tab(tab[3], "add", 3);
  tab[4] = fill_name_tab(tab[4], "sub", 3);
  tab[5] = fill_name_tab(tab[5], "and", 3);
  tab[6] = fill_name_tab(tab[6], "or", 2);
  tab[7] = fill_name_tab(tab[7], "xor", 3);
  tab[8] = fill_name_tab(tab[8], "zjmp", 4);
  tab[9] = fill_name_tab(tab[9], "ldi", 3);
  tab[10] = fill_name_tab(tab[10], "sti", 3);
  tab[11] = fill_name_tab(tab[11], "fork", 4);
  tab[12] = fill_name_tab(tab[12], "lld", 3);
  tab[13] = fill_name_tab(tab[13], "lldi", 4);
  tab[14] = fill_name_tab(tab[14], "lfork", 5);
  tab[15] = fill_name_tab(tab[15], "aff", 3);
  tab[16] = NULL;
  return (tab);
}

char	*fill_name_tab(char *result, char *str, int len)
{
  int	i;

  i = 0;
  if ((result = malloc(sizeof(char) * len + 1)) == NULL)
    my_error("", "", "Can't perform malloc.\n", 1);
  while (str[i])
    {
      result[i] = str[i];
      i++;
    }
  result[i] = '\0';
  return (result);
}
